<template>
  <div class="paddingTop search_page">
    <head-top head-title="写评论" goBack="true"></head-top>
    <div>
      <!-- <span>(暂定)创建人</span>
      <br /> -->
      <input
        type="hidden"
        v-model="comment.createPerson"
        style="width: 16rem;height:1.5rem; font-size: 0.8rem;margin-top:0.5rem"
      />


      <input
        type="hidden"
        v-model="did"
        style="width: 16rem;height:1.5rem; font-size: 0.8rem;margin-top:0.5rem"
      />
      <br />
      <span>内容</span>
      <br />
      <textarea v-model="comment.context"></textarea>
    </div>
    <button class="submit" @click="postComment()">发表</button>
  </div>
</template>

<script>
import headTop from "../../components/header/head";
import footGuide from "../../components/footer/footGuide";
import { searchRestaurant } from "../../service/getData";
import { imgBaseUrl } from "../../config/env";
import { getStore, setStore } from "../../config/mUtils";
export default {
  data() {
    return {
      id: sessionStorage.getItem("userId"),
      comment: {
        createPerson: "",
        did: "",
        context: "",
      },
    };
  },
  created: function () {
    this.userId(this.id);
    this.did1();
  },
  //  created(id){
  //   var vm=this;
  //   console.log(vm.id)
  //   this.axios({
  //     method:"get",
  //     url:"http://172.16.9.12:8081/getUserById",
  //    params:{
  //      userId:this.id

  //    },

  //   }).then(function(res){
  //       console.log(res.data);
  //       vm.comment.createPerson=res.data
  //   });
  // },
  methods: {
    userId(id) {
      console.log(id);
      var vm = this;
      console.log(vm.id);
      this.axios({
        method: "get",
        url: "http://172.16.9.12:8081/getUserById",
        params: {
          userId: this.id,
        },
      }).then(function (res) {
        console.log(res.data);
        vm.comment.createPerson = res.data;
      });
    },
    did1() {
      this.did = this.$route.query.id;
    },
    postComment() {
      var vm2 = this;
      var vm = this.axios({
        method: "post",
        params: {
          createPerson: this.comment.createPerson,
          did: this.did,
          context: this.comment.context,
        },
        url: "http://172.16.9.12:8081/house/comment/addComment",
      }).then(function () {
        vm2.$router.go(-1);
      });
    },
  },
  components: {
    headTop,
  },
};
</script>

<style>
span {
  font-size: 1.0rem;
  height: 1.5rem;
  margin-left: 0.5rem;
}
textarea {
  font-size: 0.8rem;
  width: 16rem;
  height: 7rem;
  margin-top: 0.5rem;
}
.submit {
  margin-top: 0.5rem;
  float: right;
  width: 3rem;
  height: 1.4rem;
  border-radius: 0.2rem;
  background-color: lawngreen;
  color: white;
  font-size: 0.9rem;
}
.submit:active {
  background-color: yellowgreen;
}
</style>